package ui.custom.component;

import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.util.List;
import java.util.Vector;

import javax.swing.BorderFactory;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import javax.swing.border.Border;

import ui.custom.label.AttLabel;
import ui.custom.panel.PanelPlaned;
import ui.custom.panel.PersonalPanel;
import domain.valueObejcts.Location;
import domain.valueObejcts.ProjectPosition;

/**
 * Custom bar
 * @author Marius Popa
 */
public class MyBar extends JPanel {

	private static final long serialVersionUID = 1L;

	public static final int CUST_WIDTH = 50;
	public static final int CUST_HEIGTH = 100;
	
	private Vector<PanelPlaned> panelPlaned = new Vector<PanelPlaned>();
	private Location location;
	
	public MyBar(Location location){
		super();
		this.location = location;
		GridBagLayout gbl = new GridBagLayout();
		setLayout(gbl);
		GridBagConstraints gbc = new GridBagConstraints();
		gbc.insets = new Insets(2, 2, 2, 2);
		
		gbc.gridx = 1;
		gbc.gridy = 0;
		AttLabel numberLbl = new AttLabel(location.toString(), SwingConstants.RIGHT, Font.BOLD, 20, AttLabel.BAR);
		gbl.setConstraints(numberLbl, gbc);
		add(numberLbl);
		
		for (int i = 1; i <= location.getCountPersons(); i++) {
			gbc.gridx = i;
			gbc.gridy = 1;
			PanelPlaned planed = new PanelPlaned(this);
			gbl.setConstraints(planed, gbc);
			add(planed);
			panelPlaned.add(planed);
		}
		
		Border raisedbevel = BorderFactory.createRaisedBevelBorder();
		Border loweredbevel = BorderFactory.createLoweredBevelBorder();
		Border compound = BorderFactory.createCompoundBorder(raisedbevel, loweredbevel);
		this.setBorder(compound);
		
		setBounds(location.getxPos(), location.getyPos(), 200 * location.getCountPersons(), 200);
		
	}
	
	public Location returnLocation(){
		return this.location;
	}
	
	public void setPosition(List<ProjectPosition> positions) {
		for (int i = 0; i < positions.size(); i++) {
			panelPlaned.get(i).update(positions.get(i));
		}
	}

	public void setPersonalPanel(PersonalPanel personalPanel) {
		for (PanelPlaned pan : this.panelPlaned) {
			pan.setPersonalPanel(personalPanel);
		}
	}

}
